<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
			</div>
			<div class="right-panel-search">
				<el-input v-model="search.keyword" placeholder="模块标识、名称" clearable></el-input>
				<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="configId" stripe>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="标识" prop="configId" width="300"></el-table-column>
				<el-table-column label="模块标识" prop="code" width="150"></el-table-column>
				<el-table-column label="模块名称" prop="name" width="150"></el-table-column>
				<el-table-column label="站内消息" prop="webSms" width="150">
					<template #default="scope">
						<el-button type="primary" size="small" round v-if="scope.row.webSms==='1'">可选</el-button>
						<el-button type="success" size="small" round v-else-if="scope.row.webSms==='2'">必选</el-button>
						<el-button type="info" size="small" round v-else>禁用</el-button>
					</template>
				</el-table-column>
				<el-table-column label="外部邮件" prop="emailSms" width="150">
					<template #default="scope">
						<el-button type="primary" size="small" round v-if="scope.row.emailSms==='1'">可选</el-button>
						<el-button type="success" size="small" round v-else-if="scope.row.emailSms==='2'">必选</el-button>
						<el-button type="info" size="small" round v-else>禁用</el-button>
					</template>
				</el-table-column>
				<el-table-column label="手机消息" prop="mobileSms" width="150">
					<template #default="scope">
						<el-button type="primary" size="small" round v-if="scope.row.mobileSms==='1'">可选</el-button>
						<el-button type="success" size="small" round v-else-if="scope.row.mobileSms==='2'">必选</el-button>
						<el-button type="info" size="small" round v-else>禁用</el-button>
					</template>
				</el-table-column>
				<el-table-column label="微信消息" prop="wxSms" width="150">
					<template #default="scope">
						<el-button type="primary" size="small" round v-if="scope.row.wxSms==='1'">可选</el-button>
						<el-button type="success" size="small" round v-else-if="scope.row.wxSms==='2'">必选</el-button>
						<el-button type="info" size="small" round v-else>禁用</el-button>
					</template>
				</el-table-column>
				<el-table-column label="钉钉消息" prop="ddSms" width="150">
					<template #default="scope">
						<el-button type="primary" size="small" round v-if="scope.row.ddSms==='1'">可选</el-button>
						<el-button type="success" size="small" round v-else-if="scope.row.ddSms==='2'">必选</el-button>
						<el-button type="info" size="small" round v-else>禁用</el-button>
					</template>
				</el-table-column>
				<el-table-column label="APP消息" prop="appSms" width="150">
					<template #default="scope">
						<el-button type="primary" size="small" round v-if="scope.row.appSms==='1'">可选</el-button>
						<el-button type="success" size="small" round v-else-if="scope.row.appSms==='2'">必选</el-button>
						<el-button type="info" size="small" round v-else>禁用</el-button>
					</template>
				</el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="120">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>

	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>

</template>

<script>
import saveDialog from './save'

export default {
	name: 'sysMsgConfig',
	components: {
		saveDialog
	},
	data() {
		return {
			dialog: {
				save: false
			},
			apiObj: this.$API.system.sysMsgConfig.getSysMsgConfigList,
			selection: [],
			search: {
				keyword: "",
			}
		}
	},
	mounted() {

	},
	methods: {
		add(){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		table_edit(row){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		async table_del(row, index){
			var res = await this.$API.system.sysMsgConfig.delete.post({configId: row.configId});
			if(res.code == 200){
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		handleSuccess(){
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
